home *** CD-ROM | disk | FTP | other *** search
- /* spwnprnt.c --- BIBLE pp. 97-103 */
- /* ====================== PARENT ========================= */
- #include <stdio.h>
- #include <process.h>
- #include <alloc.h>
- #include <string.h>
- typedef struct TEST_DATA
- {
- char name[20];
- int n;
- double x;
- } TEST_DATA;
- /* PARENT: Test the "spawn" functions. Pass address of
- * data in command line arguments as well as
- * environment variables when appropriate. */
- char *envp[] =
- {
- "PARENT=SPAWN FUNCTIONS",
- NULL
- };
- main()
- {
- char *argv[4],buf[20], rname[40];
- TEST_DATA *pdata;
- /* Set up a data structure and initialize it */
- if((pdata=(TEST_DATA *)
- malloc(sizeof(TEST_DATA))) == NULL) abort();
- strcpy(pdata->name, "PARENT");
- pdata->n = 100;
- pdata->x = 1000.99;
- /* Set up the arguments for the child process */
- argv[0] = "child.exe",
- argv[1] = rname;
- sprintf(buf, "%Fp", (void far *)pdata);
- argv[2] = buf;
- argv[3] = NULL;
- /* Ask user which "spawn" routine to call */
- printf("Enter name of \"spawn\" function to call:");
- gets(rname);
- strlwr(rname);
- /* Call the "spawn" function requested by the user */
- if(strcmp(rname, "spawnl") == 0)
- {
- spawnl(P_WAIT, "child.exe",
- "child.exe", "spawnl", buf, NULL);
- }
- if(strcmp(rname, "spawnle") == 0)
- {
- spawnle(P_WAIT, "child.exe",
- "child.exe", "spawnle", buf, NULL, envp);
- }
- if(strcmp(rname, "spawnlp") == 0)
- {
- spawnlp(P_WAIT, "child.exe",
- "child.exe", "spawnlp", buf, NULL);
- }
- if(strcmp(rname, "spawnlpe") == 0)
- {
- spawnlpe(P_WAIT, "child.exe",
- "child.exe", "spawnlpe", buf, NULL, envp);
- }
- if(strcmp(rname, "spawnv") == 0)
- {
- spawnv(P_WAIT, "child.exe", argv);
- }
- if(strcmp(rname, "spawnve") == 0)
- {
- spawnve(P_WAIT, "child.exe", argv, envp);
- }
- if(strcmp(rname, "spawnvp") == 0)
- {
- spawnvp(P_WAIT, "child.exe", argv);
- }
- if(strcmp(rname, "spawnvpe") == 0)
- {
- spawnvpe(P_WAIT, "child.exe", argv, envp);
- }
- /* Check if we could call child or not */
- if(strcmp(pdata->name, "CHILD") == 0)
- {
- printf("Back from child: name = %s, n = %d, x = %f\n",
- pdata->name, pdata->n, pdata->x);
- }
- else
- {
- printf("Don't know: %s\n", rname);
- }
- }